/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2020年5月21日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.lesson9.leetcode;

/**
 * @Type T20200521_JZOF_23
 * @Desc
 * @author 52489
 * @date 2020年5月21日
 * @Version V1.0
 */
public class T20200521_JZOF_23 {
    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        ListNode tmp = head;
        for (int i = 0; i < 4; i++) {
            head.next = new ListNode(i + 2);
            head = head.next;
        }
        getKthFromEnd(tmp, 2);

    }

    public static ListNode getKthFromEnd(ListNode head, int k) {
        int i = 1;
        ListNode tmp = head;
        while (null != tmp) {
            i++;
            tmp = tmp.next;
        }
        for (int j = 1; j < i - k; j++) {
            head = head.next;
        }
        return head;

    }

}
